package com.mxin.ui.list

data class PageData<T>(val page:Page, val data:List<T>?) {

    val state = PageDataState.convertState(this)

    fun getPage() = page.page

    fun getPageSize() = page.pageSize



    companion object{
        @JvmStatic
        inline fun <reified K> create(page:Int = 0, pageSize:Int = -1, data:List<K>?) : PageData<K> {
            return PageData(Page(page, if(pageSize==-1) data?.size?:0 else pageSize), data)
        }

        @JvmStatic
        inline fun <reified K> create(page:Page, data:List<K>?) : PageData<K> {
            return PageData(page, data)
        }

    }

}

/**
 *  辅助类，方便List直接转换成Page
 */
inline fun <reified K> List<K>.toPageData(page:Int = 0, pageSize:Int = -1):PageData<K>{
    return PageData.create(page, pageSize, this)
}

inline fun <reified K> List<K>.toPageData(page:Page):PageData<K>{
    return PageData.create(page, this)
}
